﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BUS;
using DTO;
namespace GUI
{
    public partial class FormXemTinhTrangBan : Form
    {
        public FormXemTinhTrangBan()
        {
            InitializeComponent();

                string btbHoaDon = "Xem Chi Tiết";
                BanAnBUS ba = new BanAnBUS();
                List<BanAnDTO> ListBanAn = new List<BanAnDTO>();
                ListBanAn = ba.LayDanhSachBanAn();
                int STT = 0;
            
                foreach (BanAnDTO singleRecord in ListBanAn)
                {
                    dataGridView1.Rows.Add(STT + 1, singleRecord.Id_Ban_An, singleRecord.Ten_Ban_An, singleRecord.Id_Khu_Vuc, btbHoaDon , singleRecord.Tinh_Trang == 1 ? "ĐANG BẬN" : "còn trống");
                    STT++;
                }

            
            
        }
        public static int tempIDBanAn;
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 4) //Assuming the button column as second column, if not can change the index
            {

                //check if anything needs to be validated here
                if (Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString().CompareTo("còn trống")))
                {
                    
                    tempIDBanAn = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());
                    FormLapPhieuHoaDon f = new FormLapPhieuHoaDon();
                    f.Show();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Bàn Này Chưa Đặt!");
                    return;
                }
                

            }
        }
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void FormXemTinhTrangBan_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
